package com.tarena.lbs.basic.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.pojo.param.AreaParam;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理区域 地市数据业务的接口类
 */
@Tag(name = "区域服务", description = "区域服务")
@RestController
public class AreaController {


    @Autowired
    private AreaService areaService;

    @Operation(summary = "查询省级地区列表")
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> queryProvinces(){
        List<AreaVO> areaList = areaService.areaList(null);
        System.out.println(areaList);
        return new Result<>(areaList);
    }

    @Operation(summary = "查询地市列表")
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> queryChildren(@PathVariable("parentId") Integer parentId){
        List<AreaVO> children = areaService.areaList(parentId);
        return new Result<>(children);
    }

    @Operation(summary = "查询地市树")
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        List<AreaVO> areaVOS=areaService.regionTree();
        return new Result<>(areaVOS);
    }

    @Operation(summary = "查询所有城市列表")
    @GetMapping("/admin/basic/area/cityList")
    public Result<List<AreaVO>> cityList(AreaParam param){
        // 获取所有城市（depth=2表示市级别）
        List<AreaVO> cityList = areaService.cityList(param);
        return new Result<>(cityList);
    }


}
